package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.validator.ChannelAdd;
import com.heima.model.common.validator.ChannelUpdate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "频道管理",tags = "频道管理")
@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController {
    //根据条件分页查询频道列表
    @Autowired
    private AdChannelService adChannelService;

    @ApiOperation("查询全部频道")
    @GetMapping("/channels")

    public ResponseResult findAll() {
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }

    @ApiOperation("频道分页列表查询")
    @PostMapping("/list")
    public ResponseResult findList(@RequestBody ChannelDto dto) {

        return adChannelService.findByNameAndPage(dto);
    }

    @ApiOperation("新增频道")
    @PostMapping("/save")
    public ResponseResult addAdChannel(@RequestBody @Validated({ChannelAdd.class}) AdChannel adChannel){
        return adChannelService.addChannel(adChannel);
    }

    @ApiOperation("修改频道")
    @PostMapping("/update")
    public ResponseResult updateAdChannel(@RequestBody @Validated({ChannelUpdate.class}) AdChannel adChannel){
        return adChannelService.updateChannel(adChannel);
    }

    @ApiOperation("删除频道")
    @GetMapping("/del/{id}")
    public ResponseResult deleteAdChannel(@PathVariable Integer id){
        return adChannelService.deleteChannel(id);
    }
}
